package com.tqw.order.controller;

import com.tqw.entity.JWTUtil;
import com.tqw.entity.Result;
import com.tqw.item.feign.ItemFeignClient;
import com.tqw.order.service.OrderService;
import com.tqw.order.vo.OrderConfirmVO;
import com.tqw.order.vo.OrderPayInfoVO;
import com.tqw.order.vo.OrderPaySuccessVO;
import com.tqw.order.vo.OrderSubmitVO;
import com.tqw.pojo.Item;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: czm
 * @Date: 2022/04/07/16:49
 * @Description:
 */
@RestController
@RequestMapping("/order/")
public class OrderController {

    @Autowired
    private OrderService orderService;


    /**
     * 生成确定订单页
     * @param itemId
     * @return
     */
    @GetMapping("/orderItemInfo/{itemId}")
    public Result getOrderItemInfo(@RequestHeader("Authorization") String token,@PathVariable("itemId") Integer itemId){
        Integer clientId = JWTUtil.getId(token);
        OrderConfirmVO orderConfirmVO = orderService.getOrderItemInfo(clientId, itemId);
        Result<OrderConfirmVO> result = new Result<>();
        result.setData(orderConfirmVO);
        return result;
    }

    /**
     * 提交订单
     * @param orderSubmitVO
     * @return
     */
    @PostMapping("/submit")
    public Result submitOrder(@RequestHeader("Authorization") String token,@RequestBody OrderSubmitVO orderSubmitVO){
        Integer clientId = JWTUtil.getId(token);
        Result result = orderService.submit(clientId, orderSubmitVO);
        return  result;
    }

    /**
     * 订单支付信息
     */
    @GetMapping("/orderPayInfo/{orderId}")
    public Result getOrderPayInfo(@PathVariable("orderId") String orderId){
        OrderPayInfoVO orderPayInfo = orderService.getOrderPayInfo(orderId);
        Result<OrderPayInfoVO> result = new Result<>();
        result.setData(orderPayInfo);
        return result;
    }

    /**
     * 订单支付
     */
    @PutMapping("/toPay")
    public Result orderToPay(@RequestBody OrderPayInfoVO orderPayInfoVO){
        orderService.orderPay(orderPayInfoVO);
        return new Result();
    }

    /**
     * 订单支付成功信息
     */
    @GetMapping("/orderPaySuccessInfo/{orderId}")
    public Result getOrderPaySuccessInfo(@PathVariable String orderId){
        OrderPaySuccessVO orderPaySuccessVO = orderService.getOrderPaySuccessInfo(orderId);
        Result<OrderPaySuccessVO> result = new Result<>();
        result.setData(orderPaySuccessVO);
        return result;
    }


}
